/* 
 * File:   usart.h
 * Author: Tetsuya Idota
 *
 * Header file for usart.c
 */

#ifndef USART_H
#define	USART_H

#include <inttypes.h>

// Refer to http://www.nongnu.org/avr-libc/user-manual/group__util__setbaud.html

// Feel free to modify this struct to include parameters you would like to be
// able to control
typedef struct tagusart_config
{
	uint8_t number;
	//float baudrate;     // or uint32_t if you prefer
	uint32_t baudrate;
	uint8_t databits;
	uint8_t paritymode;
	uint8_t stopbits;
    
	// fill this in with whatever features you want to use.
} usart_config;

void configure_usart( usart_config *Ux );

// Use something like these . or
void usart0tx( uint8_t data );
void usart1tx( uint8_t data );
void usart2tx( uint8_t data );
void usart3tx( uint8_t data );
uint8_t usart0rx();
uint8_t usart1rx();
uint8_t usart2rx();
uint8_t usart3rx();
// use something like these
void usartNtx( uint8_t N, uint8_t data );
uint8_t usartNrx( uint8_t N );
// or both

// Possible to use macros, too, instead of either...
#define TXUSARTn(d,n) while ( !( UCSR##n##A & (1<<UDRE##n)) ); UDR##n = d

#endif	/* USART_H */

